package chai.ningning.creation;

/**
 * 1、通过继承 Thread 类并重写 run 方法可以实现自定义的 线程类
 * 2、该类中可以根据需要来定义 成员变量、成员方法、构造方法
 */
public class PrimeNumberThread extends Thread{

    private int bound;

    public PrimeNumberThread(String name,int bound) {
        super(name);
        this.bound = bound;
    }

    private boolean isPrime(int n){
        for (int i = 2; i < n; i++) {
            if (n % i == 0){
                return false;
            }
        }
        return true;
    }

    @Override
    public void run() {
       Thread thread = Thread.currentThread();
       System.out.println(thread.getName());

        for (int i = 2; i < bound; i++) {
            if (isPrime(i)){
                System.out.print(i + " ");
            }
        }
        System.out.println();
    }
}
